﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.EntityFramework.DbContexts;
using Ids4Review.AuthorizationServer.Data;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Ids4Review.AuthorizationServer
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args)
                .MigrateDbContext<UserContext>((ctx, services) =>
                {
                    new UserContextSeed().SeedAsync(ctx, services)
                    .Wait();
                })
                  .MigrateDbContext<ConfigurationDbContext>((ctx, services) =>
                  {
                      new ConfigurationContextSeed().SeedAsync(ctx, services)
                      .Wait();
                  })
                   .MigrateDbContext<PersistedGrantDbContext>((ctx, services) =>
                   {
                       new PersistedGrantContextSeed().SeedAsync(ctx, services)
                       .Wait();
                   })
                .Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
            .UseUrls("http://+:5000")
                .Build();
    }
}
